<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人基本信息修改</title>

    <%@ include file="base.jsp" %>

    <link rel="stylesheet" href="css/x-admin.css" media="all"/>
    <script src="lib/layui/layui.js" charset="utf-8"></script>
    <script src="js/x-layui.js" charset="utf-8"></script>
    <script src="js/jquery-3.6.0.js"></script>
    <script>
        $(function () {
            var tid = ${sessionScope.tteacher.tid};
            $.ajax({
                url: '<%=request.getContextPath()%>/admin/teacherController',
                data: {
                    "fun": "getTeacher",
                    "tid": tid
                },
                dataType: 'json',
                success(data) {
                    $('#tphone').val(data.tphone)
                    $('#temail').val(data.temail)

                    let sex = data.tsex;
                    if (sex === '男') {
                        $('#nan').attr('checked', 'checked')
                    } else {
                        $('#nv').attr('checked', 'checked')
                    }
                }
            })


        })
    </script>
    <script>

        //前端校验
        //onsubmit 事件是提交时触发，如果事件触发的函数返回false，表单不提交，如果返回true，表单提交
        function checkForm() {
            var tsex = $(":radio:checked[name=tsex]")
            var tphone = document.getElementById("tphone").value;
            var temail = document.getElementById("temail").value;

            if (tsex.length == 0) {
                alert("请选择性别");
                return false;
            }
            if (null == tphone || tphone == '') {
                alert("请输入手机号");
                return false;
            }
            if (null == temail || temail == '') {
                alert("请输入email");
                return false;
            }
            x_admin_close();
            return true;
        }
    </script>
</head>

<body>
<div class="x-body">
    <form action="teacher/teacherOwnController" method="post" target="_parent" onsubmit="return checkForm();">
        <input type="hidden" name="fun" value="update"/>
        <input type="hidden" name="tid" value="${sessionScope.tteacher.tid}"/>

        <div style="color: #1e9fff">其他信息修改请向管理员提交申请</div>
        <div id="msg" style="color: red"></div>
        <div class="layui-form-item">
            <label class="layui-form-label"> <span class="x-red">*</span>性别
            </label>
            <div class="layui-input-inline">
                <label for="nan">
                    <input
                            <c:if test="${sessionScope.tteacher.tsex == '男'}">checked</c:if> type="radio" name="tsex"
                            id="nan" value="男" class="layui-btn-radius">
                    男
                </label>
                <label for="nv">
                    <input
                            <c:if test="${sessionScope.tteacher.tsex == '女'}">checked</c:if> type="radio" name="tsex"
                            id="nv" value="女" class="layui-btn-radius">
                    女
                </label>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>必填
            </div>
        </div>

        <div class="layui-form-item">
            <label for="tphone" class="layui-form-label"> <span class="x-red">*</span>手机号
            </label>
            <div class="layui-input-inline">
                <input id="tphone" type="text" name="tphone" class="layui-input"
                       value="${sessionScope.tteacher.tphone}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>必填
            </div>
        </div>

        <div class="layui-form-item">
            <label for="temail" class="layui-form-label"> <span class="x-red">*</span>email
            </label>
            <div class="layui-input-inline">
                <input id="temail" name="temail" class="layui-input" value="${sessionScope.tteacher.temail}">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="x-red">*</span>必填
            </div>
        </div>

        <div class="layui-form-item">
            <label for="" class="layui-form-label"></label>
            <button type="submit" class="layui-btn">修改</button>
        </div>
    </form>
</div>
</body>

</html>